﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using EnvDTE;

namespace SSISPackageExplorer.Config
{
    public class SSISPackageExplorerConfig
    {
        public List<PackageFolder> PackageFolderList { get; set; }
        public List<Package> PackageList { get; set; }

        public SSISPackageExplorerConfig() 
        {
            this.PackageList = new List<SSISPackageExplorer.Config.Package>();
            this.PackageFolderList = new List<SSISPackageExplorer.Config.PackageFolder>();
        }

        public void Save(Project project) 
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(SSISPackageExplorerConfig));
                FileStream fs = new FileStream(Session.GetProjectConfigFile(project) + "\\SSISPackageExplorerConfig.xml", FileMode.Create);
                serializer.Serialize(fs, this);
                fs.Close();
            }
            catch 
            { 
            }

         }

        public static SSISPackageExplorerConfig Load(Project project) 
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(SSISPackageExplorerConfig));
                FileStream fs = new FileStream(Session.GetProjectConfigFile(project), FileMode.Open);
                SSISPackageExplorerConfig result = (SSISPackageExplorerConfig)serializer.Deserialize(fs);
                fs.Close();
                return result;
            }
            catch
            { 
            }
            return new SSISPackageExplorerConfig();
        }
    }
}
